package com.muyu.product.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.product.domain.RuleAttrInfo;
import com.muyu.product.domain.req.RuleAttrInfoQueryReq;
import com.muyu.product.domain.req.RuleAttrInfoSaveReq;
import com.muyu.product.domain.req.RuleAttrInfoEditReq;
import com.muyu.product.service.RuleAttrInfoService;
import com.muyu.common.core.web.page.TableDataInfo;

/**
 * 规格详情Controller
 *
 * @author DongZeLiang
 * @date 2024-02-27
 */
@Api(tags = "规格详情")
@RestController
@RequestMapping("/ruleAttr")
public class RuleAttrInfoController extends BaseController {
    @Autowired
    private RuleAttrInfoService ruleAttrInfoService;

    /**
     * 查询规格详情列表
     */
    @ApiOperation("获取规格详情列表")
    @RequiresPermissions("product:ruleAttr:list")
    @GetMapping("/list")
    public Result<TableDataInfo<RuleAttrInfo>> list(RuleAttrInfoQueryReq ruleAttrInfoQueryReq) {
        startPage();
        List<RuleAttrInfo> list = ruleAttrInfoService.list(RuleAttrInfo.queryBuild(ruleAttrInfoQueryReq));
        return getDataTable(list);
    }

    /**
     * 导出规格详情列表
     */
    @ApiOperation("导出规格详情列表")
    @RequiresPermissions("product:ruleAttr:export")
    @Log(title = "规格详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RuleAttrInfo ruleAttrInfo) {
        List<RuleAttrInfo> list = ruleAttrInfoService.list(ruleAttrInfo);
        ExcelUtil<RuleAttrInfo> util = new ExcelUtil<RuleAttrInfo>(RuleAttrInfo.class);
        util.exportExcel(response, list, "规格详情数据");
    }

    /**
     * 获取规格详情详细信息
     */
    @ApiOperation("获取规格详情详细信息")
    @RequiresPermissions("product:ruleAttr:query")
    @GetMapping(value = "/{id}")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
    public Result<RuleAttrInfo> getInfo(@PathVariable("id") Long id) {
        return Result.success(ruleAttrInfoService.getById(id));
    }

    /**
     * 新增规格详情
     */
    @RequiresPermissions("product:ruleAttr:add")
    @Log(title = "规格详情", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增规格详情")
    public Result<String> add(@RequestBody RuleAttrInfoSaveReq ruleAttrInfoSaveReq) {
        return toAjax(ruleAttrInfoService.save(RuleAttrInfo.saveBuild(ruleAttrInfoSaveReq)));
    }

    /**
     * 修改规格详情
     */
    @RequiresPermissions("product:ruleAttr:edit")
    @Log(title = "规格详情", businessType = BusinessType.UPDATE)
    @PutMapping("/{id}")
    @ApiOperation("修改规格详情")
    public Result<String> edit(@PathVariable Long id, @RequestBody RuleAttrInfoEditReq ruleAttrInfoEditReq) {
        return toAjax(ruleAttrInfoService.updateById(RuleAttrInfo.editBuild(id,ruleAttrInfoEditReq)));
    }

    /**
     * 删除规格详情
     */
    @RequiresPermissions("product:ruleAttr:remove")
    @Log(title = "规格详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除规格详情")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1,2,3,4")
    public Result<String> remove(@PathVariable List<Long> ids) {
        return toAjax(ruleAttrInfoService.removeBatchByIds(ids));
    }
}
